package com.justgame.project.service.art.feign;

import com.alibaba.fastjson.JSONObject;
import com.justgame.project.cloud.common.entity.RedisZSetScore;
import com.justgame.project.cloud.common.util.AppContextUtils;
import com.justgame.project.service.api.feign.IArtPageInfoClient;
import com.justgame.project.service.art.aspect.ArtPageInfoAspect;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author ZhouWeiBo
 * @create 2022/4/19
 */
@RestController
@AllArgsConstructor
public class ArtPageInfoClient implements IArtPageInfoClient {

    @Override
    @PostMapping(REFRESH_PAGE_NUM)
    public Boolean refreshPageNum(@RequestBody String jsonStr, @RequestParam("numKey")String numKey) {
        try {
            List<RedisZSetScore> viewNum = JSONObject.parseArray(jsonStr, RedisZSetScore.class);
            ArtPageInfoAspect aspect = AppContextUtils.getBean(ArtPageInfoAspect.class);
            aspect.writeAboutPageNum2(viewNum, numKey);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
}
